#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author： 胡浩浩
# datetime： 2021/12/28 15:46 
# ide： PyCharm
from sqlalchemy.orm import Session
from Models.environmentModel import environment_model
from Schemas.environmentSchema import environment_schema


def get_environment_by_id(db: Session, environment_id: int):
    return db.query(environment_model.Environment).filter(environment_model.Environment.id == environment_id).first()


def get_environment_list(db: Session, skip: int = 0, limit: int = 10):
    return db.query(environment_model.Environment).offset(skip).limit(limit).all()


def create_environment(db: Session, environment: environment_schema.EnvironmentCreate):
    db_environment = environment_model.Environment(**environment.dict())
    db.add(db_environment)
    db.commit()
    db.refresh(db_environment)

    return db_environment
